; NVIDIA Display Driver uninstaller
killapp nvCplUI.exe
call Uninstall

[UninstallSilent]
Set ForceNoReboot=yes
call UninstallSilentReboot

[UninstallSilentReboot]
Set Silent=yes
call Uninstall
Delreg {UninstRegkey}\NVIDIA Display Driver

[Uninstall]
; echo Uninstall
SysCallAndWait MsiExec /x{F4469132-EA9F-444A-BFFB-323C7413E951} /quiet /norestart
SysCallAndWait MsiExec /x{71807498-D8E2-41C6-84CD-8ED7A076B6EC} /quiet /norestart
SysCallAndWait {syswow64dir}\nViewSetup -s -uninstall
enumregcmd HKLM\SYSTEM\CurrentControlSet\Control\Video\{*},call EnumVideoKeys
; echo InfPath : {InfPath}
CheckPath INFCHECK={windir}\Inf\{InfPath}
if {INFCHECK}=TRUE then call RunDpinst

; echo Old Version = {Version}
set OldVersion={Version}
enumregcmd HKLM\SYSTEM\CurrentControlSet\Control\Video\{*},call EnumVideoKeys
; echo New Version = {Version}
if {Version}={OldVersion} then call ManualRemove

call CleanUp

; Hack to trigger a reboot
Copy {current Script},{sysdir}\deleteme.txt
DelBoot {sysdir}\deleteme.txt

[ManualRemove]
RemoveDevice pci,VEN_10DE,Display

[RunDpinst]
SysCallAndWait {sysdir}\dpinst.exe /u {windir}\Inf\{InfPath} /s

[CleanUp]
; echo Cleaning stuff up

; echo deleting the "Portal" game related items
del {windir}\nvidia icons\Portal_32x32.ico
del {windir}\nvidia icons\Portal_48x48.ico
GetFolderPath Desktop=25
del {Desktop}\Play Portal Now.lnk

set NVIDIADriverFound=FALSE
enumregcmd HKLM\SYSTEM\CurrentControlSet\Control\Video\{*},call EnumVideoKeys
if {InBoxDriverFound}=TRUE then call LeaveInBox
if {NVIDIADriverFound}=FALSE then call DeleteAll

set NVIDIADriverFound=FALSE
enumregcmd HKLM\SYSTEM\CurrentControlSet\Control\Video\{*},call EnumVideoKeysForDelete

[EnumVideoKeysForDelete]
set Found0000=FALSE
set Service
set MyBaseKey={Current Root Key}\{Current Reg Key}
enumregcmd {MyBaseKey}\{*},call CheckNVIDIAVideoKeys
if {Service}%nv then if {Found0000}=FALSE then DelReg {Current Root Key}\{Current Reg Key}

[EnumVideoKeys]
set MyBaseKey={Current Root Key}\{Current Reg Key}
enumregcmd {MyBaseKey}\{*},call CheckNVIDIAVideoKeys

[CheckNVIDIAVideoKeys]
set DriverDesc=FOOBAR
; echo Current Root Key : {Current Root Key}
; echo Current Reg Key : {Current Reg Key}
GetReg DriverDesc={Current Root Key}\{Current Reg Key}\DriverDesc
; echo DriverDesc: {DriverDesc}
if {DriverDesc}%NVIDIA then set NVIDIADriverFound=TRUE
if {DriverDesc}%NVIDIA then if {DriverDesc}%Microsoft then set InBoxDriverFound=TRUE
if {DriverDesc}%NVIDIA then GetReg InfPath={Current Root Key}\{Current Reg Key}\InfPath
if {DriverDesc}%NVIDIA then GetReg Version={Current Root Key}\{Current Reg Key}\DriverVersion
if {DriverDesc}%NVIDIA then GetReg CoInstaller={Current Root Key}\{Current Reg Key}\Uninstall\CoInstaller
; echo Version: {Version}
GetReg Service={Current Root Key}\{Current Reg Key}\Service
if {Current Reg Key}%0000 then set Found0000=TRUE


[DeleteAll]
; echo No NVIDIA driver.  Deleting all NVIDIA files.
delboot {sysdir}\nvapi.dll
delboot {sysdir}\nvapi64.dll
delboot {sysdir}\nvd3dum.dll
delboot {sysdir}\nvd3dumx.dll
Delboot {sysdir}\drivers\nvlddmkm.sys

delboot {syswow64dir}\nvapi.dll
delboot {syswow64dir}\nvd3dum.dll
call LeaveInBox

DelReg HKCR\VirtualStore\MACHINE\SOFTWARE\NVIDIA Corporation\Global
DelRegE HKCR\VirtualStore\MACHINE\SOFTWARE\NVIDIA Corporation
DelReg HKLM\Software\NVIDIA Corporation\Global\NvCplApi
DelReg HKCU\Software\NVIDIA Corporation\Global\NvCplApi
DelReg HKLM\Software\NVIDIA Corporation\Global\NVTweak
DelReg HKCU\Software\NVIDIA Corporation\Global\NVTweak
DelReg HKLM\Software\NVIDIA Corporation\Global\MediaCenterTray
DelReg HKLM\Software\NVIDIA Corporation\Global\Hybrid\Action
DelReg HKLM\Software\NVIDIA Corporation\Global\Hybrid
DelRegE HKLM\Software\NVIDIA Corporation\Global
DelReg HKLM\Software\NVIDIA Corporation\Installer
Delreg {UninstRegkey}\NVIDIA Display Driver
DelReg HKLM\Software\NVIDIA Corporation\NVAPI
DelReg HKLM\SYSTEM\{*ControlSet}\Services\nv\NVAPI
DelReg HKLM\SYSTEM\{*ControlSet}\Services\nvlddmkm\NVAPI
DelReg HKLM\SYSTEM\{*ControlSet}\Services\nvlddmkm


[LeaveInBox]
; echo NVIDIA Inbox driver found.  Leaving InBox Files

call UninstallSedona

UninstallService NVSvc

delboot {sysdir}\nvwgf2um.dll
delboot {sysdir}\nvwgf2umx.dll
Delboot {sysdir}\nvmctray.dll
Delboot {sysdir}\nvoglv32.dll
delboot {sysdir}\nvoglv64.dll
Delboot {sysdir}\nvsvc.dll
Delboot {sysdir}\nvsvcr.dll
Delboot {sysdir}\nvsvc64.dll
Delboot {sysdir}\nvmccs.dll
Delboot {sysdir}\nvmccsrs.dll
Delboot {sysdir}\nvvsvc.exe
Delboot {sysdir}\nvcolor.exe
Delboot {sysdir}\nvapps.xml
Delboot {sysdir}\nvwsapps.xml
Delboot {sysdir}\nvcod.dll
Delboot {sysdir}\nvcodins.dll
Delboot {sysdir}\nvcodh.dll
Delboot {sysdir}\nvcodhins.dll
Delboot {sysdir}\nvudisp.exe
DelBoot {sysdir}\{CoInstaller}
DelBoot {wrkdir}\nvapps.xml
DelBoot {wrkdir}\nvwsapps.xml
DelBoot {wrkdir}\NvStarted
DelBoot {pgmdir}\nvModes.dat
DelBoot {pgmdir}\nvModes.001



delboot {syswow64dir}\nvwgf2um.dll
Delboot {syswow64dir}\nvoglv32.dll
Delboot {syswow64dir}\nvapps.xml

delreg HKLM\Software\Microsoft\Windows\CurrentVersion\Run\NvMediaCenter
delreg HKLM\Software\Microsoft\Windows\CurrentVersion\Run\NvCplDaemon
delreg HKLM\Software\Microsoft\Windows\CurrentVersion\Run\NvSvc
delreg HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\DontShowMeThisDialogAgain\RestoreProfile
delreg HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\DontShowMeThisDialogAgain\RestoreGlobals



[UninstallSedona]
; echo Uninstalling Sedona
SysCallAndWait {sysdir}\regsvr32.exe /s /u {sysdir}\nvcpl.dll
SysCallAndWait {sysdir}\regsvr32.exe /s /u {sysdir}\nvmccs.dll
SysCallAndWait {sysdir}\regsvr32.exe /s /u {sysdir}\nvmccss.dll
SysCallAndWait {sysdir}\regsvr32.exe /s /u {sysdir}\nvdisps.dll
SysCallAndWait {sysdir}\regsvr32.exe /s /u {sysdir}\nvgames.dll
SysCallAndWait {sysdir}\regsvr32.exe /s /u {sysdir}\nvmobls.dll
SysCallAndWait {sysdir}\regsvr32.exe /s /u {sysdir}\nvvitvs.dll
SysCallAndWait {sysdir}\regsvr32.exe /s /u {sysdir}\nvwss.dll
SysCallAndWait {sysdir}\regsvr32.exe /s /u {sysdir}\nvsvc.dll
SysCallAndWait {sysdir}\regsvr32.exe /s /u {sysdir}\nvsvc64.dll
SysCallAndWait {sysdir}\regsvr32.exe /s /u {sysdir}\nvvsvc.exe

Delboot {sysdir}\nvcpl.dll
Delboot {sysdir}\nvdisps.dll
Delboot {sysdir}\nvgames.dll
Delboot {sysdir}\nvmccss.dll
Delboot {sysdir}\nvmccs.dll
Delboot {sysdir}\nvmobls.dll
Delboot {sysdir}\nvvitvs.dll
Delboot {sysdir}\nvwss.dll
Delboot {sysdir}\nvhotkey.dll
Delboot {sysdir}\oemdspif.dll

Set current file
DirAndApply {windir}\help\nvcpl\nvcpl*.cab,Delboot {current file}
Set current file
DirAndApply {windir}\help\nvcpl\nvdsp*.chm,Delboot {current file}
Set current file
DirAndApply {windir}\help\nvcpl\nv3d*.chm,Delboot {current file}
Set current file
DirAndApply {windir}\help\nvcpl\nvmob*.chm,Delboot {current file}
Set current file
DirAndApply {windir}\help\nvcpl\nvwks*.chm,Delboot {current file}
Set current file
DirAndApply {wrkdir}\*.NVP,Delboot {current file}

Set ServersPresent=0
EnumRegNamesCmd HKLM\Software\NVIDIA Corporation\NVControlPanel\RegisteredServers, set ServersPresent=1
EnumRegNamesCmd HKLM\Software\NVIDIA Corporation\Global\NVControlPanel\RegisteredServers, set ServersPresent=1
if {ServersPresent}=0 then call UninstallSedonaClient

[UninstallSedonaClient]
; echo Uninsatlling Sedona Client
Delboot {sysdir}\nvcpl.exe
Delboot {sysdir}\nvcplui.exe
Delboot {sysdir}\nvcpl.cpl
Delboot {sysdir}\nvcpluir.dll
Delboot {sysdir}\nvexpbar.dll
Delboot {sysdir}\nvdispsr.dll
Delboot {sysdir}\nvgamesr.dll
Delboot {sysdir}\nvmccssr.dll
Delboot {sysdir}\nvmoblsr.dll
Delboot {sysdir}\nvvitvsr.dll
Delboot {sysdir}\nvwssr.dll

Set current file
DirAndApply {windir}\help\nvcpl\nvcpl*.chm,Delboot {current file}
Del {windir}\help\nvcpl
DelReg HKLM\Software\NVIDIA Corporation\NVControlPanel
DelRegE HKLM\Software\NVIDIA Corporation
DelReg HKCU\Software\NVIDIA Corporation\NVControlPanel
DelRegE HKCU\Software\NVIDIA Corporation
DelReg HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\NVHotkey


set Shortcutpath={CommonPrograms}\NVIDIA Corporation\NVIDIA Control Panel
set ShortcutName=Control Panel.lnk
call DelShortCut
delboot {CommonPrograms}\NVIDIA Corporation

[DelShortCut]
del {Shortcutpath}\{ShortcutName}
delboot {Shortcutpath}
